home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoQueryTrader.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  5.3 KB  |  179 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.  * Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef __ko_query_trader_h__
  21. #define __ko_query_trader_h__
  22.  
  23. #include <kservice.h>
  24. #include <ksharedptr.h>
  25. #include <qvaluelist.h>
  26. #include <koffice_export.h>
  27.  
  28. class QObject;
  29. class QStringList;
  30. class KoDocument;
  31. class KoFilter;
  32. class KoFilterChain;
  33.  
  34. /**
  35.  *  Represents an available KOffice component
  36.  *  that supports the document interface.
  37.  */
  38. class KOFFICECORE_EXPORT KoDocumentEntry
  39. {
  40.  
  41. public:
  42.   KoDocumentEntry() { m_service = 0L; } // for QValueList
  43.   KoDocumentEntry( KService::Ptr service );
  44.   ~KoDocumentEntry() { }
  45.  
  46.   KService::Ptr service() const { return m_service; }
  47.  
  48.   /**
  49.    * @return TRUE if the service pointer is null
  50.    */
  51.   bool isEmpty() const { return m_service == 0L; }
  52.  
  53.   /**
  54.    * @return name of the associated service
  55.    */
  56.   QString name() const { return m_service->name(); }
  57.  
  58.   /**
  59.    *  Mimetypes (and other service types) which this document can handle.
  60.    */
  61.   QStringList mimeTypes() const { return m_service->serviceTypes(); }
  62.  
  63.   /**
  64.    *  @return TRUE if the document can handle the requested mimetype.
  65.    */
  66.   bool supportsMimeType( const QString & _mimetype ) const
  67.   { return mimeTypes().contains( _mimetype ); }
  68.  
  69.   /**
  70.    *  Uses the factory of the component to create
  71.    *  a document. If that is not possible, 0 is returned.
  72.    */
  73.   KoDocument* createDoc( KoDocument* parent = 0, const char* name = 0 ) const;
  74.  
  75.   /**
  76.    *  This function will query ksycoca to find all available components.
  77.    *  The result will only contain parts, which are embeddable into a document
  78.    *
  79.    *  @param _constr is a constraint expression as used by KTrader.
  80.    *                 You can use it to set additional restrictions on the available
  81.    *                 components.
  82.    */
  83.   static QValueList<KoDocumentEntry> query( const QString &  _constr = QString::null );
  84.  
  85.   /**
  86.    *  This function will query the system to find all available filters.
  87.    *
  88.    *  @param _onlyDocEmb specifies if only KOffice Parts should be listed which are
  89.    *                 embeddable into other koDocuments, or all (if false)
  90.    *                 (eg.: it makes no sense to embed Kexi into KWord,
  91.    *                 but it makes sense to embed it into KoShell)
  92.    *  @param _constr is a constraint expression as used by KDEDs trader interface.
  93.    *                 You can use it to set additional restrictions on the available
  94.    *                 components.
  95.    */
  96.   // ### TODO: MERGE WITH ABOVE METHODE WHEN BIC+SIC CHANGES ARE ALLOWED
  97.   static QValueList<KoDocumentEntry> query( bool _onlyDocEmb,const QString& _constr);
  98.   /* this is how the signature should be looking after merging
  99.   static QValueList<KoDocumentEntry> query( bool _onlyDocEmb =true, const QString& _constr = QString::null );
  100.   or better: use an enum for the first arg.
  101.   */
  102.  
  103.  
  104.   /**
  105.    *  This is a convenience function.
  106.    *
  107.    *  @return a document entry for the KOffice component that supports
  108.    *          the requested mimetype and fits the user best.
  109.    */
  110.   static KoDocumentEntry queryByMimeType( const QString & mimetype );
  111.  
  112. private:
  113.   KService::Ptr m_service;
  114. };
  115.  
  116. /**
  117.  *  Represents an available filter.
  118.  */
  119. class KoFilterEntry : public KShared
  120. {
  121.  
  122. public:
  123.   typedef KSharedPtr<KoFilterEntry> Ptr;
  124.  
  125.   KoFilterEntry() : weight( 0 ) { m_service = 0L; } // for QValueList
  126.   KoFilterEntry( KService::Ptr service );
  127.   ~KoFilterEntry() { }
  128.  
  129.   KoFilter* createFilter( KoFilterChain* chain, QObject* parent = 0, const char* name = 0 );
  130.  
  131.   /**
  132.    *  The imported mimetype(s).
  133.    */
  134.   QStringList import;
  135.  
  136.   /**
  137.    *  The exported mimetype(s).
  138.    */
  139.   QStringList export_;
  140.  
  141.   /**
  142.    *  The "weight" of this filter path. Has to be > 0 to be valid.
  143.    */
  144.   unsigned int weight;
  145.  
  146.   /**
  147.    *  Do we have to check during runtime?
  148.    */
  149.   QString available;
  150.  
  151.   /**
  152.    *  @return TRUE if the filter can import the requested mimetype.
  153.    */
  154.   bool imports( const QString& _mimetype ) const
  155.   { return ( import.contains( _mimetype ) ); }
  156.  
  157.   /**
  158.    *  @return TRUE if the filter can export the requested mimetype.
  159.    */
  160.   bool exports( const QString& _m ) const
  161.   { return ( export_.contains( _m ) ); }
  162.  
  163.   /**
  164.    *  This function will query KDED to find all available filters.
  165.    *
  166.    *  @param _constr is a constraint expression as used by KDEDs trader interface.
  167.    *                 You can use it to set additional restrictions on the available
  168.    *                 components.
  169.    */
  170.   static QValueList<KoFilterEntry::Ptr> query( const QString& _constr = QString::null );
  171.  
  172.   KService::Ptr service() const { return m_service; }
  173.  
  174. private:
  175.   KService::Ptr m_service;
  176. };
  177.  
  178. #endif
  179.